import About from "../pages/About"
import Home from "../pages/Home"
import News from "../pages/News"
import Message from "../pages/Message"
import User from "../pages/User"
import UserDetail from "../pages/UserDetail"
import Test from "../pages/Test"
const routes = [
  {name:"About",path:"/About",component:About},
  {
    path:"/Home",
    component:Home,
    children:[
      // path:不能以/开头
      {path:"News",component:News},
      {path:"Message",component:Message},
      {path:"",redirect:"News"}
    ]
  },
  {
    path:"/User",
    component:User,
    children:[
      // props:true 相当于将id数据(params)通过props形式传递给了UserDetail
      // {path:":id",component:UserDetail,props:true}

      // props:obj 相当于将obj中的数据通过props形式传递给了UserDetail
      // {path:":id",component:UserDetail,props:{id:1,a:"aaa",b:"bbb"}}

      // props:fn 相当于将fn返回的数据通过props形式传递给了UserDetail
      // fn的第一个参数是路由对象
      {
        name:"UserDetail",
        path:":id",
        component:UserDetail,
        props:({params:{id},query:{a,b},hash})=>({id,a,b,hash})
      }

        //冗余
        /*props:(route)=>{
          // route : 路由对象
          return {
            id:route.params.id,
            a:route.query.a,
            b:route.query.b,
            hash:route.hash
          }
        }}*/
    ]
  },
  {path:"/Test/:id?",component:Test},
  {path:"/",redirect:"/About"}
]

export default routes
